package com.hnevc.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

class Person implements Serializable{
	int id;
	String name;
	int age;
	public Person(int id, String name, int age){
		this.id = id;
		this.name = name;
		this.age = age;
	}
}

public class ObjectStreamDemo {

	public static void main(String[] args) throws Exception{	
		Person p = new Person(1, "tom", 23);
		FileOutputStream fos = new FileOutputStream("D:\\object.txt");
		ObjectOutputStream out = new ObjectOutputStream(fos);
		out.writeObject(p);
		out.close();
		FileInputStream fis = new FileInputStream("D:\\object.txt");
		ObjectInputStream in = new ObjectInputStream(fis);
		Person p2 = (Person) in.readObject();
		in.close();
		System.out.println(p2.name);
	}

}
